<?php

/**
 * Created by PhpStorm.
 * User: huqi
 * Date: 17/6/15
 * Time: PM5:01
 */
namespace App\Http\Controllers\backend ;
use App\Http\Controllers\Controller;
use Request;

class Base extends Controller
{
    public $isJson = false ;
    public $isPost = false ;

    public function __construct()
    {
        $this->isJson = ! (strpos(strtolower(Request::header('accept')), 'application/json') === false ) ;
        $this->isPost = Request::getMethod() == 'POST' ;
    }

    public function view($view,$data = []){
        return view("backend.{$view}",$data) ;
    }

    public function page($model){
        $page = intval(Request::get('p',1)) ;
        $pageszie = 10 ;
        $skip = $pageszie * ($page -1 ) ;

        $ret = [] ;
        $ret['code'] = 0 ;
        $ret['total'] = $model->count();
        $ret['current'] = $page ;
        $ret['rows']=$model->skip($skip)->take($pageszie)->get() ;
        return $ret ;
    }
}